﻿
    using Chain.BLL;
//    using ChainStock.Controls;
    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public partial class RptEmptyBills : PageBase
    {
        private OrderDetail bllOrderDetail = new OrderDetail();
        private OrderLog bllOrderLog = new OrderLog();


        private void BindEmptyBillsList(string strSql)
        {
            int Counts = this.NetPagerParameter.RecordCount;
            strSql = strSql + " and OrderType=3";
            strSql = strSql + " and Mem.MemID = OrderLog.OrderMemID and OrderLog.OrderShopID = SysShop.ShopID and OrderLog.OrderUserID = SysUser.UserID";
            strSql = PubFunction.GetShopAuthority(base._UserShopID, "OrderShopID", strSql);
            DataTable dtEmptyBills = this.bllOrderLog.GetListSP(this.NetPagerParameter.PageSize, this.NetPagerParameter.CurrentPageIndex, out Counts, new string[] { strSql }).Tables[0];
            this.NetPagerParameter.RecordCount = Counts;
            this.NetPagerParameter.CustomInfoHTML = string.Format("<div class=\"results\"><span>当前第{0}/{1}页 共{2}条记录 每页{3}条</span></div>", new object[] { this.NetPagerParameter.CurrentPageIndex, this.NetPagerParameter.PageCount, this.NetPagerParameter.RecordCount, this.NetPagerParameter.PageSize });
            this.rptEmptyBillsList.DataSource = dtEmptyBills;
            this.rptEmptyBillsList.DataBind();
            PageBase.BindSerialRepeater(this.rptEmptyBillsList, this.NetPagerParameter.PageSize * (this.NetPagerParameter.CurrentPageIndex - 1));
        }

        protected void btnRptEmptyBillsExcel_Click(object sender, EventArgs e)
        {
            OrderLog bllOrderLog = new OrderLog();
            int Counts = this.NetPagerParameter.RecordCount;
            string strSql = this.QueryCondition() + " and OrderType=3" + " and Mem.MemID = OrderLog.OrderMemID and OrderLog.OrderShopID = SysShop.ShopID and Mem.MemUserID = SysUser.UserID";
            strSql = PubFunction.GetShopAuthority(base._UserShopID, "OrderShopID", strSql);
            DataTable dtEmptyBills = bllOrderLog.GetListSP(0x186a0, 1, out Counts, new string[] { strSql }).Tables[0];
            DataExcelInfo.EmptyBillsExcel(dtEmptyBills, base._UserName);
        }

        protected void btnRptEmptyBillsQuery_Click(object sender, EventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = 1;
            this.BindEmptyBillsList(this.QueryCondition());
        }

        protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = 1;
            this.NetPagerParameter.PageSize = int.Parse(this.drpPageSize.SelectedValue);
            this.BindEmptyBillsList(this.QueryCondition());
        }

        protected string GetGoodsType(int intGoodsType, float strNumber)
        {
            switch (intGoodsType)
            {
                case 0:
                    return "普通商品";

                case 1:
                    return "服务项目";
            }
            return "";
        }

        protected void NetPagerParameter_PageChanging(object src, PageChangingEventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = e.NewPageIndex;
            this.BindEmptyBillsList(this.QueryCondition());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                PubFunction.BindMemLevelSelect(this.sltMemLevelID, true);
                this.txtStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy-MM-dd");
                this.txtEndTime.Value = DateTime.Now.ToString("yyyy-MM-dd");
                PubFunction.BindShopSelect(base._UserShopID, this.sltShop, true);
                this.chkAllowPwd.Checked = PubFunction.curParameter.bolPwd;
                this.BindEmptyBillsList(this.QueryCondition());
                if ((PubFunction.curParameter.dataAuthority == 1) && (base._UserShopID > 1))
                {
                    this.sltShop.Value = this._UserShopID.ToString();
                    this.sltShop.Attributes.Add("disabled", "disabled");
                }
            }
        }

        protected string QueryCondition()
        {
            string strQueryMem = this.txtQueryMem.Value;
            string strMemLevelID = this.sltMemLevelID.Value;
            string strMemShopID = this.sltShop.Value;
            string strRemark = PubFunction.RemoveSpace(this.txtRemark.Value);
            string strOrderAccount = PubFunction.RemoveSpace(this.txtOrderAccount.Value);
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" 1=1 ");
            if (strQueryMem != "")
            {
                strSql.AppendFormat(" and (MemCard = '{0}' or MemName like '%{0}%' or MemMobile = '{0}' or MemCardNumber = '{0}' )", strQueryMem);
            }
            if (strMemLevelID != "")
            {
                strSql.AppendFormat(" and MemLevelID={0}", int.Parse(strMemLevelID));
            }
            if (strMemShopID != "")
            {
                strSql.AppendFormat(" and OrderShopID={0}", int.Parse(strMemShopID));
            }
            if (this.txtStartTime.Value != "")
            {
                strSql.AppendFormat(" and OrderCreateTime>='{0}' ", this.txtStartTime.Value);
            }
            if (this.txtEndTime.Value != "")
            {
                strSql.AppendFormat(" and OrderCreateTime<='{0}'", PubFunction.TimeEndDay(this.txtEndTime.Value));
            }
            if (strRemark != "")
            {
                strSql.AppendFormat(" and OrderRemark like '%{0}%' ", strRemark);
            }
            if (strOrderAccount != "")
            {
                strSql.AppendFormat(" and OrderAccount='{0}'", strOrderAccount);
            }
            return strSql.ToString();
        }

        protected void rptEmptyBillsList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                DataRowView dr = (DataRowView) e.Item.DataItem;
                Repeater rptItem = (Repeater) e.Item.FindControl("rptEmptyBillsDetailList");
                if (rptItem != null)
                {
                    int recordCount = this.NetPagerParameter.RecordCount;
                    string strSql = " OrderDetail.OrderID=OrderLog.OrderID and OrderDetail.GoodsID=Goods.GoodsID";
                    strSql = strSql + " and OrderDetail.OrderID=" + dr["OrderID"];
                    DataTable dtDetail = this.bllOrderDetail.GetListSP(strSql).Tables[0];
                    rptItem.DataSource = dtDetail;
                    rptItem.DataBind();
                    foreach (RepeaterItem rp in rptItem.Items)
                    {
                        Label lblDetailNum = (Label) rp.FindControl("lblDetailNumber");
                        lblDetailNum.Text = (rp.ItemIndex + 1).ToString();
                    }
                }
            }
        }
    }


